package com.example.a14110100409.yuejiandemo.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.adapter.ClassInfoAdapter;
import com.example.a14110100409.yuejiandemo.adapter.ClubListAdapter;
import com.example.a14110100409.yuejiandemo.adapter.TieziListAdapter;
import com.example.a14110100409.yuejiandemo.fragment.ClubFragment;
import com.example.a14110100409.yuejiandemo.javabean.Club;
import com.example.a14110100409.yuejiandemo.javabean.UserShaitu;
import com.example.a14110100409.yuejiandemo.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UserTieziActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private String user_photo;
    private String user_name;
    private ImageView user_pic,shaitulist_return;
    private Context context;
    private int user_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_tiezi);
        shaitulist_return = (ImageView) findViewById(R.id.shaitulist_return);
        shaitulist_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        context=UserTieziActivity.this;
        user_id = getApplication().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("user_id",0);
        user_name = getIntent().getStringExtra("user_name");
        recyclerView = (RecyclerView) findViewById(R.id.user_tiezi_rv);
        showData();
    }
    private void showData(){
        //context=UserTieziActivity.this;
        UserModel userModel = new UserModel();
        Call<List<UserShaitu>> call = userModel.getusershaitu(user_id);
        call.enqueue(new Callback<List<UserShaitu>>() {
            @Override
            public void onResponse(Call<List<UserShaitu>> call, Response<List<UserShaitu>> response) {
                List<UserShaitu>  mDataList = response.body();
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(manager);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setAdapter(new TieziListAdapter(UserTieziActivity.this,mDataList,user_name));
            }

            @Override
            public void onFailure(Call<List<UserShaitu>> call, Throwable t) {
                Toast.makeText(context,"jjjj",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
